package com.atguigu.gmall.item.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 李旭
 * @date 2021/10/12 11:15
 * @Description:
 */
@Configuration
public class ThreadConfig {

    //线程池
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        return new ThreadPoolExecutor(
                10,//核心线程
                20,//最大线程
                5,// 闲置线程的存活时间  == 最大线程-核心线程
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(30),
                //工厂
                //拒绝策略
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
    }
}
